#![allow(unused)]
use rand::Rng;
use std::io::{self,Write};
use std::cmp::Ordering;

fn main() {
    println!("猜数字游戏！！！");
    
    let number:i32 = rand::thread_rng().gen_range(0..101);
    loop{
        let mut input =String::new();

        print!("请输入一个数字：");
        io::stdout().flush();
        io::stdin().read_line(&mut input).expect("输入错误！");

        let input:i32 = match input.trim().parse() {
            Ok(s) => s,
            Err(_) => continue,
        };
        
        match input.cmp(&number){
            Ordering::Less => println!("太小了！"),
            Ordering::Greater => println!("太大了！"),
            Ordering::Equal => {
                println!("正确！");
                break;
            },
        }
    }
}
